/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package projecteuler;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
/**
 *
 * @author ChunchO
 */
public class Problem067 {
	static List<int[]> p;

	public static void main(String[ ]args){
		p = getPyramid("problem067.txt");
		for(int i = p.size()-1;i>=1;i--)
		{
			int[] topRow = p.get(i-1);
			int[] botRow = p.get(i);
			for(int j = 0; j<topRow.length;j++)
				topRow[j] += botRow[j] > botRow[j+1]?botRow[j]:botRow[j+1];
		}
		System.out.println(p.get(0)[0]);
	}

	public static List<int[]> getPyramid(String path){
		BufferedReader  br;
		List<int[]> piramide;
		piramide = new ArrayList();
		try{
			br = new BufferedReader(new FileReader(path));
			String line = br.readLine();
			int i = 0;
			while(line != null)
			{
				String[] s = line.split(" ");
				int[] row = new int[s.length];
				for(int j = 0;j<s.length;j++)
					row[j] = Integer.parseInt(s[j]);
				piramide.add(row);
				i++;
				line = br.readLine();
			}
			return piramide;
		}catch(java.io.IOException e)
		{
		}
		return null;
	}
}

